<?php
include_once('DB.class.php');

class Utils {
	public $myDb=false;
	function __construct($dbObj=false) {
		$this->myDb = $dbObj;
	}

	function addPickToEvent($eventId, $pickType, $halftimepick, $halftimepicktext, $publicDate = '0000-00-00 00:00:00') {
		$sql = "insert into Picks (p_pick, p_pt_id, p_initdate, p_text, p_publicdate) VALUES(?, ?, NOW(), ?, ?)";		
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $halftimepick),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $pickType),
		array(DB::DB_STRING_PARAMETER_CHAR, $halftimepicktext),
		array(DB::DB_STRING_PARAMETER_CHAR, $publicDate)
		);
		$lastPickId = $this->myDb->getIdFromInsert($sql, $params);

		//insert into EventPicks
		$sql = "insert into EventPicks (ep_e_id, ep_p_id) VALUES(?, ?)";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $eventId),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $lastPickId));
		$lastEventPickId = $this->myDb->getIdFromInsert($sql, $params);
		if(!($lastEventPickId)) {
			error_log(__FILE__ . " " . __LINE__ . "noLastEventPickID");
			return false;
		}
		
		
	}

	function addPick($sport, $league, $gametype, $visteam, $hometeam, $starttime, $pick, $subject, $text, $eventType, $pickType, $publicDate) {
		$success=false;
		//insert into Events
		$sql = "insert into Events (e_et_id, e_starttime, e_home_team, e_vis_team) VALUES(?, ?, ?, ?)";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $eventType),
						array(DB::DB_STRING_PARAMETER_CHAR, $starttime),
						array(DB::DB_STRING_PARAMETER_CHAR, $hometeam),
						array(DB::DB_STRING_PARAMETER_CHAR, $visteam)
		);
		
		
		$lastEventId = $this->myDb->getIdFromInsert($sql, $params);
		if(!($lastEventId)) { //fails
			error_log(__FILE__ . " " . __LINE__ . "noLastEventID");
			return false;
		}

		//insert into picks
		$sql = "insert into Picks (p_pick, p_pt_id, p_initdate, p_status, p_text, p_publicdate) VALUES(?, ?, ?, ?, ?, ?)";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $pick),
						array(DB::DB_INTEGER_PARAMETER_CHAR, $pickType),
						array(DB::DB_STRING_PARAMETER_CHAR, date('Y-m-d G:i:s')),
						array(DB::DB_STRING_PARAMETER_CHAR, 'p'),
						array(DB::DB_STRING_PARAMETER_CHAR, $text),
						array(DB::DB_STRING_PARAMETER_CHAR, $publicDate)
		);
		
		$lastPickId = $this->myDb->getIdFromInsert($sql, $params);
		if(!($lastPickId)) {
			error_log(__FILE__ . " " . __LINE__ . "noLastPickID");
			return false;
		}
		
		//insert into EventPicks
		$sql = "insert into EventPicks (ep_e_id, ep_p_id) VALUES(?, ?)";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $lastEventId),
						array(DB::DB_INTEGER_PARAMETER_CHAR, $lastPickId));
		$lastEventPickId = $this->myDb->getIdFromInsert($sql, $params);
		if(!($lastEventPickId)) {
			error_log(__FILE__ . " " . __LINE__ . "noLastEventPickID");
			return false;
		}
		return $success;		
	}

	function deletePick($pId) {
		$sql = 'delete from Picks where p_id = ?';
		$params = array(
		array(DB::DB_INTEGER_PARAMETER_CHAR, $pId));
		return $this->myDb->getIdFromInsert($sql, $params);
	}
	
	function updatePickStatus($status, $pId) {
		$sql = 'update Picks set p_status = ? where p_id = ?';
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $status),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $pId));
		return $this->myDb->getIdFromInsert($sql, $params);
	}
	
	function makePickWinner($pId) {
		return $this->updatePickStatus(HTGConstants::PICK_WINNER_STATUS, $pId);
	}

	function makePickLoser($pId) {
		return $this->updatePickStatus(HTGConstants::PICK_LOSER_STATUS, $pId);
	}

	function makePickPush($pId) {
		return $this->updatePickStatus(HTGConstants::PICK_PUSH_STATUS, $pId);
	}
	
	
	function getAllPicks() {
	  $sql = "select * from Events, EventPicks, Picks, EventTypes where e_et_id = et_id and ep_e_id = e_id and ep_p_id = p_id order by e_starttime DESC, p_id ASC LIMIT 10";
	  $results = $this->myDb->getSQLResults($sql);
	  return $results;
	}
	
	function getAllPicksByLeagueId($leagueId) {
		$sql = "select * from Events, EventTypes, EventPicks, Picks where ep_e_id = e_id and ep_p_id = p_id and e_et_id = et_id and et_l_id = ? order by e_starttime DESC, p_id DESC LIMIT 5";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $leagueId));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}

	function getNotificationSettings($uid) {
		$sql = "select * from NotificationSettings where ns_u_id = ?";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $uid));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}
	
	function disableNotification($nsId) {
		//update nsDisabledYN = 'Y'
		$sql = "update NotificationSettings set ns_disabledYN = 'Y' where ns_id = ?";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $nsId));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}
	
	function enableNotification($nsId) {
		//update nsDisabledYN = 'Y'
		$sql = "update NotificationSettings set ns_disabledYN = 'Y' where ns_id = ?";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $nsId));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}
	
	function addNotification($name, $value){
		
	}
	
	function addUser($email, $password) {
		$email = strtolower($email);
		$sql = "insert into Users (u_email, u_password) VALUES(?, ?)";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $email),
		array(DB::DB_STRING_PARAMETER_CHAR, $password));
		
		$lastUserId = $this->myDb->getIdFromInsert($sql, $params);
		if(!($lastUserId)) {
			//fails
			error_log(__FILE__ . " " . __LINE__ . " INSERT into Users FAIL  -- noLastEventID:" . $sql);
			return false;
		}
		$this->sendWelcomeEmail($email, $password);
		error_log(__FILE__ . " " . __LINE__ . "  " . $lastUserId);
		return $lastUserId;		
	}
		
	function getUser($userEmail) {
		$sql = "select * from Users where u_email = ?";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $userEmail));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}

	function getMembershipTypeById($id) {
		$sql = "select * from MembershipTypes where mt_id = ?";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $id));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;		
	}

	function addMembership($userId, $myMemberShipType) {
		$expirationDate = '0000-00-00';
		
		
		$membershipTypeResults = $this->getMembershipTypeById($myMemberShipType);
		$membershipLength = $membershipTypeResults[0]['mt_duration'];
		
		if($membershipLength != NULL) {
			//compute expiration date
			$expirationDate = strftime( '%Y-%m-%d', time() + ($membershipLength * 86400));   //there are 86,400 seconds in a day
		}
		
		$sql = "insert into Memberships (m_u_id, m_mt_id, m_expires, m_initdate) VALUES(?, ?, ?, NOW())";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $userId),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $myMemberShipType ),
		array(DB::DB_STRING_PARAMETER_CHAR, $expirationDate)
		);
		
		$lastUserId = $this->myDb->getIdFromInsert($sql, $params);
		if(!($lastUserId)) {
			//fails
			error_log(__FILE__ . " " . __LINE__ . " INSERT into Memberships FAIL  -- noLastMembershipID");
			return false;
		}
		return $lastUserId;
	}

	function addPurchaseAttempt($pppId=1, $procTranId='', $response='', $authKey='', $status='p') {
		$sql = "insert into PurchaseAttempts (pa_ppp_id, pa_initdate, pa_response, pa_responsedate, pa_authkey, pa_status, pa_proctranid) 
		VALUES(?, NOW(), ?, NOW(), ?, ?, ?)";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $pppId),
		array(DB::DB_STRING_PARAMETER_CHAR, $response ),
		array(DB::DB_STRING_PARAMETER_CHAR, $authKey),
		array(DB::DB_STRING_PARAMETER_CHAR, $status),
		array(DB::DB_STRING_PARAMETER_CHAR, $procTranId)
		);
		
		return $this->myDb->getIdFromInsert($sql, $params);
				
	}

	function getPurchaseAttempts($authKey, $status='p', $paResponse='Completed') {
		$sql = "select * from PurchaseAttempts where pa_authkey = ? and pa_status = ? and pa_response = ? order by pa_initdate DESC";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $authKey),
			array(DB::DB_STRING_PARAMETER_CHAR, $status),
			array(DB::DB_STRING_PARAMETER_CHAR, $paResponse)
		);
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}

	function addPurchase($paId, $pppId, $uId) {
		$sql = "insert into Purchases (p_pa_id, p_ppp_id, p_initdate, p_u_id) VALUES(?, ?, NOW(), ?)";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $paId),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $pppId ),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $uId)
		);
		
		return $this->myDb->getIdFromInsert($sql, $params);
	}
	
	
	function getMembership($membershipId) {
		$sql = "select * from Memberships where m_id = ?";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $membershipId));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;		
	}
	
	function getActiveMemberships($membershipId) {
		$sql = "select * from Memberships where m_u_id = ? and (m_expires = '0000-00-00' OR m_expires IS NULL OR m_expires > NOW())";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $membershipId));
		$results = $this->myDb->getSQLResults($sql, $params);
		return $results;
	}
	
	function addMembershipPurchase($mId, $pId) {
		$sql = "insert into MembershipPurchases (mp_m_id, mp_p_id) VALUES(?, ?)";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $mId),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $pId )
		);
		
		return $this->myDb->getIdFromInsert($sql, $params);
	}
	
	function getRecentEvents() {
		return $this->getAllPicks();
	}
	
	
	function addPromo($name, $url) {
		$sql = "insert into PromoTools (pt_name, pt_url) VALUES(?, ?)";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $name),
		array(DB::DB_STRING_PARAMETER_CHAR, $url )
		);
		
		return $this->myDb->getIdFromInsert($sql, $params);
	}
	
	function returnTableOfPicks() {
		$myStr = "";
		//display all the posts
		$results = $this->getAllPicks();
		$firstRow=true;

		if($results) {
			$myStr .= '<table >';

			$isFirst=true;
			$lastEventId;
			foreach($results as  $recordNum => $myResult) {
				//display  header line
				if($isFirst) {
					$myStr .= '<tr>';
					$myStr .= '<th>' . '&nbsp;' . '</th>';
					$myStr .= '<th>' . '&nbsp;' . '</th>';
					$myStr .= '<th>' . 'Pick' . '</th>';
					$myStr .= '<th>' . 'Vis' . '</th>';
					$myStr .= '<th>' . '&nbsp;' . '</th>';
					$myStr .= '<th>' . 'Home' . '</th>';
					$myStr .= '<th>' . 'League' . '</th>';
					$myStr .= '<th>' . 'Game Start' . '</th>';
					$myStr .= '<th>' . 'Created' . '</th>';
					$myStr .= '<th>' . 'Pick Text' . '</th>';

					$myStr .= '</tr>';
					$isFirst=false;
				}

				//display each record
				$myStr .= '<tr>';

				//Delete Pick
				$myStr .= '<td><form method="POST" action="' .  $_SERVER['PHP_SELF'] . '" id="deleteFormNN"/>
				<input type="image" name="submit" src="images/red_x.png" border="0" height="25" width="25">
				<input type="hidden" name="action" value="delete" />
				<input type="hidden" name="p_id" value="' . $myResult['p_id'] . '" />
				</form></td>';
				
				$pickStatus = $myResult['p_status'];
				if($pickStatus != HTGConstants::PICK_WINNER_STATUS) { 
					//Make Pick a Winner
					$myStr .= '<td><form method="POST" action="' .  $_SERVER['PHP_SELF'] . '" id="deleteFormNN"/>
				<input type="image" name="submit" src="images/thumbs_up.png" border="0" height="25" width="25">
				<input type="hidden" name="action" value="mkwin" />
				<input type="hidden" name="p_id" value="' . $myResult['p_id'] . '" />
				</form></td>';
				} else {
					$myStr .= '<td><img src="images/thumbs_up_filled.png" border="0" height="25" width="25" /></td>';
				}

				if($pickStatus != HTGConstants::PICK_LOSER_STATUS)				{
					//Make Pick a Loser
					$myStr .= '<td><form method="POST" action="' .  $_SERVER['PHP_SELF'] . '" id="deleteFormNN"/>
				<input type="image" name="submit" src="images/thumbs_down.png" border="0" height="25" width="25">
				<input type="hidden" name="action" value="mklose" />
				<input type="hidden" name="p_id" value="' . $myResult['p_id'] . '" />
				</form></td>';
				} else {
					$myStr .= '<td><img src="images/thumbs_down_filled.png" border="0" height="25" width="25" /></td>';
				}
				
				if($pickStatus != HTGConstants::PICK_PUSH_STATUS)				{
					//Make Pick a push
					$myStr .= '<td><form method="POST" action="' .  $_SERVER['PHP_SELF'] . '" id="deleteFormNN"/>
								<input type="image" name="submit" src="images/push.png" border="0" height="25" width="25">
								<input type="hidden" name="action" value="mkpush" />
								<input type="hidden" name="p_id" value="' . $myResult['p_id'] . '" />
								</form></td>';
				} else {
					$myStr .= '<td><img src="images/push_filled.png" border="0" height="25" width="25" /></td>';
				}
				
				
				
				$myStr .= '<td>' . $myResult['p_pick'] . '</td>';
				$myStr .= '<td class="visTeamCell">' . $myResult['e_vis_team'] . '</td>';
				$myStr .= '<td>' . '@' . '</td>';
				$myStr .= '<td>' . $myResult['e_home_team'] . '</td>';
				$myStr .= '<td>' . 'NFL' . '</td>';
				$myStr .= '<td>' . @date("y-m-d", @strtotime($myResult['e_starttime'])) . '</td>';
				$myStr .= '<td>' . @date("y-m-d", @strtotime($myResult['p_initdate'])) . '</td>';
				$myStr .= '<td class="pickText">' . substr($myResult['p_text'], 0, 128) . '</td>';

				$myStr .= '</tr>';
				$lastEventId = $myResult['e_id'];

			}
			$myStr .= '</table>';
		}
		return $myStr;

	}

	function isPaidMember($membershipId) {
		$memberships = $this->getActiveMemberships($membershipId);
		foreach($memberships as $recordNum => $record) {
			if($record['m_mt_id'] == 2)	{
				return true;
			}
		}
		return false;
	}
	
	function isPickPublic($pickRecord) {
		$publicDateString = $pickRecord['p_publicdate']; 
		if( $publicDateString == '0000-00-00 00:00:00' ||  @mktime()  > @strtotime($publicDateString)) {
			return true;
		}
		return false;
	}
	
	function returnMiniTableOfPicks() {
		$myStr = false;
		//display all the posts
		$results = $this->getAllPicks();
		$firstRow=true;
	
		if($results) {
			
			
			$isPaidMember=false;
			if(isset($_SESSION['u_id'])) {
				$this->isPaidMember($_SESSION['u_id']);
			}
			$myStr .= '<table >';
	
			$isFirst=true;
			$lastEventId;
			$pickIsPublic=false;
			
			foreach($results as  $recordNum => $myResult) {
				$isPublic = $this->isPickPublic($myResult);
				//display  header line
				if($isFirst) {
					$myStr .= '<tr>';
					$myStr .= '<th>' . 'Pick' . '</th>';
					$myStr .= '<th>' . 'Vis' . '</th>';
					$myStr .= '<th>' . '&nbsp;' . '</th>';
					$myStr .= '<th>' . 'Home' . '</th>';
					$myStr .= '<th>' . 'League' . '</th>';
					$myStr .= '<th>' . 'Game Start' . '</th>';	
					$myStr .= '</tr>';
					$isFirst=false;
				}
	
				if(@$myResult['e_id'] == @$lastEventId) {
					//display each record
					$myStr .= '<tr>';
					$myStr .= '<td>';
					if($isPaidMember || $isPublic) {
						$myStr .= $myResult['p_pick'];
					} else {
						$myStr .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="LDG8EDTSAKK8N"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>'; //'<img src="images/buy_now.png" />';
						
					}
					$myStr .= '</td>';
					$myStr .= '<td class="visTeamCell">' . $myResult['e_vis_team'] . '</td>';
					$myStr .= '<td>' . '@' . '</td>';
					$myStr .= '<td>' . $myResult['e_home_team'] . '</td>';
					$myStr .= '<td class="leagueCell">' . $myResult['et_short_desc'] . '</td>';
					$myStr .= '<td>' . @date("y-m-d", @strtotime($myResult['e_starttime'])) . '</td>';						
					$myStr .= '</tr>';
	
				} else {
	
					//display each record
					$myStr .= '<tr>';
					$myStr .= '<td>';
					if($isPaidMember || $isPublic) {
						$myStr .= $myResult['p_pick'];
					} else {
						@$wrongvarmyStr .= '<img src="images/buy_now.png" />';
						$myStr .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="LDG8EDTSAKK8N"><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>';
					}
					$myStr .= '</td>';
					
					$myStr .= '<td class="visTeamCell">' . $myResult['e_vis_team'] . '</td>';
					$myStr .= '<td>' . '@' . '</td>';
					$myStr .= '<td>' . $myResult['e_home_team'] . '</td>';
					$myStr .= '<td class="leagueCell">' . $myResult['et_short_desc'] . '</td>';
					$myStr .= '<td>' . @date("y-m-d", @strtotime($myResult['e_starttime'])) . '</td>';	
					$myStr .= '</tr>';
					$lastEventId = $myResult['e_id'];
				}
			}
			$myStr .= '</table>';
		}
		return $myStr;
	
	}
	
	
	function getAllSports() {
		$sql = "select * from Sports";
		$results = $this->myDb->getSQLResults($sql);
		return $results;
	}
	
	function get_include_contents($filename) {
		if (is_file($filename)) {
			ob_start();
			include $filename;
			return ob_get_clean();
		}
		return false;
	}
	
	
	/**
	Validate an email address.
	Provide email address (raw input)
	Returns true if the email address has the email
	address format and the domain exists.
	*/
	function validEmail($email)
	{
		$isValid = true;
		$atIndex = strrpos($email, "@");
		if (is_bool($atIndex) && !$atIndex)
		{
			$isValid = false;
		}
		else
		{
			$domain = substr($email, $atIndex+1);
			$local = substr($email, 0, $atIndex);
			$localLen = strlen($local);
			$domainLen = strlen($domain);
			if ($localLen < 1 || $localLen > 64)
			{
				// local part length exceeded
				$isValid = false;
			}
			else if ($domainLen < 1 || $domainLen > 255)
			{
				// domain part length exceeded
				$isValid = false;
			}
			else if ($local[0] == '.' || $local[$localLen-1] == '.')
			{
				// local part starts or ends with '.'
				$isValid = false;
			}
			else if (preg_match('/\\.\\./', $local))
			{
				// local part has two consecutive dots
				$isValid = false;
			}
			else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
			{
				// character not valid in domain part
				$isValid = false;
			}
			else if (preg_match('/\\.\\./', $domain))
			{
				// domain part has two consecutive dots
				$isValid = false;
			}
			else if
			(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
			str_replace("\\\\","",$local)))
			{
				// character not valid in local part unless
				// local part is quoted
				if (!preg_match('/^"(\\\\"|[^"])+"$/',
				str_replace("\\\\","",$local)))
				{
					$isValid = false;
				}
			}
			
			/** disabling for now cmondor **/
// 			if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
// 			{
//			//domain not found in DNS
// 				$isValid = false;
// 			}
			}
			return $isValid;
		}
	
	function insertForgottenPassword($userId, $confirmId) {
		$sql = "insert into ForgottenPasswords (fp_u_id, fp_key, fp_initdate) VALUES(?, ?, NOW())";
		$params = array(array(DB::DB_INTEGER_PARAMETER_CHAR, $userId),
		array(DB::DB_STRING_PARAMETER_CHAR, $confirmId)
		);
		
		$lastEventId = $this->myDb->getIdFromInsert($sql, $params);
		
	}

	function getBlogEntries($type = 0) {
		if($type < 1) {
			$sql = "select * from BlogEntries order by be_initdate DESC limit 10";
			return $this->myDb->getSQLResults($sql);
		} else {
			$sql = "select * from BlogEntries where be_type = ? order by be_initdate DESC limit 10";
			$params = array(
			array(DB::DB_INTEGER_PARAMETER_CHAR, $type)
			);
			return $this->myDb->getSQLResults($sql, $params);
		}
	}
	
	function addBlogPost($title, $subject, $type) {
		$sql = "insert into BlogEntries (be_initdate, be_title, be_text, be_type) VALUES(NOW(), ?, ?, ?)";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $title),
		array(DB::DB_STRING_PARAMETER_CHAR, $subject ),
		array(DB::DB_INTEGER_PARAMETER_CHAR, $type)
		);
		
		$lastBlogEntryId = $this->myDb->getIdFromInsert($sql, $params);
	}

	
	function addTicker($expireDate, $text, $url) {
		$sql = "insert into Tickers (t_expire_date, t_href_url, t_text, t_initdate) VALUES(?, ?, ?, NOW())";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $expireDate),
		array(DB::DB_STRING_PARAMETER_CHAR, $url),
		array(DB::DB_STRING_PARAMETER_CHAR, $text)
		);
		
		$lastTickerId = $this->myDb->getIdFromInsert($sql, $params);
	}
	
	function deleteTicker($tId) {
		$sql = 'delete from Tickers where t_id = ?';
		$params = array(
		array(DB::DB_INTEGER_PARAMETER_CHAR, $tId));
		return $this->myDb->getIdFromInsert($sql, $params);
	}
	
	function getCurrentTickers() {
		$sql = "select * from Tickers where t_expire_date > NOW() order by t_initdate ASC";
		return $this->myDb->getSQLResults($sql);
	}
	
	function returnTickerAdminTable() {
		$tickers = $this->getCurrentTickers();

		$isFirst=1;
		$myStr="";
		foreach($tickers as $myResult) {
			if($isFirst) {
				$myStr .= '<table id="tickerAdminTable"><tr>';

				$myStr .= '<th>' . '&nbsp;' . '</th>'; //del button column
				$myStr .= '<th>' . 'Ticker' . '</th>';
				$myStr .= '<th>' . 'Created' . '</th>';
				$myStr .= '<th>' . 'Expires' . '</th>';
					
				$myStr .= '</tr>';
				$isFirst=false;
			}
				
			//display each record
			$myStr .= '<tr>';
			$myStr .= '<td><form method="POST" action="' .  $_SERVER['PHP_SELF'] . '" id="deleteFormNN"/>
			<input type="image" name="submit" src="images/red_x.png" border="0" height="25" width="25">
			<input type="hidden" name="action" value="delete" />
			<input type="hidden" name="t_id" value="' . $myResult['t_id'] . '" />
			</form></td>';
			$myStr .= '<td>' . $myResult['t_text'] . '</td>';
			$myStr .= '<td>' . @date("y-m-d", @strtotime($myResult['t_initdate'])) . '</td>';
			$myStr .= '<td>' . @date("y-m-d", @strtotime($myResult['t_expire_date'])) . '</td>';
			$myStr .= '</tr>';
		}// end foreach
		$myStr .= '</table>';
		return $myStr;
	}
	
	function getPaidMemberNumbers() {
		return array("+3109231726");
	}

	function getPaidMemberEmails() {
		$sql = "select * from Memberships, Users where u_id = m_u_id and (m_expires = '0000-00-00' OR m_expires IS NULL OR m_expires > NOW()) and m_mt_id <> 1";
		return 	$this->myDb->getSQLResults($sql);	
	}
	
	function recordPOST() {
		$sql = "insert into POSTs (po_initdate, po_remote_ip, po_request_url) VALUES(NOW(), '" . $_SERVER['REMOTE_ADDR']  . "', ? )";
		$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $_SERVER['PHP_SELF']));
		$postId = $this->myDb->getIdFromInsert($sql, $params);
		
		foreach($_REQUEST as $name => $value) {
			$sql = "insert into POSTedVars (pv_initdate, pv_name, pv_po_id, pv_value) VALUES(NOW(), ?, ?, ?)";
			$params = array(array(DB::DB_STRING_PARAMETER_CHAR, $name),
			array(DB::DB_STRING_PARAMETER_CHAR, $postId ),
			array(DB::DB_STRING_PARAMETER_CHAR, $value )
			);
			$lastPostdId = $this->myDb->getIdFromInsert($sql, $params);
		}
	}

	
	function sendWelcomeEmail($email, $password) {
		$to = $email;
		$subject = 'Welcome to HalfTime Genius.';
		//$message = 'THIS IS THE WELCOME MESSAGE ARASH HASN\'T COMPLETED YET.  Your username is your email address: ' . $email . ' and your password is ' . $password . '.  Also you will need to go here: http://halftimegenius.com/ppl.php.php';
		//$message = 'Welcome to halftimegenius.com. Thank you for choosing us as your number 1 sports authority. We have built our reputation one client at a time and look forward to earning your business one game at a time. Feel free to contact us at 855-Win-Half. Or follow us via twitter and facebook under halftimegenius. Looking forward to see you on the winning side,
//Halftimegenius Staff';
		$message = "Welcome to halftimegenius.com and thanks for signing up with us. We are the best at HalfTime Sports opinions, and you're about to figure out why.


NFL - The nfl page is where you can go to find our realtime picks on all the latest NFL action.  We're usually making about 4 to 7 picks a weekend for NFL.
http://halftimegenius.com/nfl.php

NCAA - The ncaa page is where you can go to find our realtime picks on all the latest NCAA Football games.  Just like the NFL page you can see our real time picks.
http://halftimegenius.com/ncaaf.php

Bread and Butter - If you were wondering what HalfTime Genius actually makes money doing, go here and read up some more on why we think we're the best and more of what you can expect from us.
http://halftimegenius.com/butter.php

HELP - For help or any questions you think might be common, head on over to our Help page. If you can't find what you're looking for there, be sure to contact us Toll Free at 855 WIN-HALF toll free or send us an email halftimegenius@gmail.com
http://halftimegenius.com/help.php

HEADLINES - We update content threw out the day, so make sure you check out latest news on games, injuries, line movements, and more.
http://halftimegenius.com/blog.php

NEWS TICKER - You can check out our Live news ticker for any promotions or important news right on the home page.
http://halftimegenius.com/

FREE PICKS - We will give out free picks to the public about once a week. Check out the news ticker daily for possible free picks.
http://halftimegenius.com/

FORGOT PASSWORD - If you ever forget your password, you can go here.
http://halftimegenius.com/reset.php


Thanks again, we look forward to serving you,
Halftimegenius";
		$headers = 'From: "HalfTime Genius" <halftimegenius@gmail.com>' . "\r\n" .
			    'Reply-To: halftimegenius@gmail.com' . "\r\n" .
			    'X-Mailer: PHP/' . phpversion();
		mail($to, $subject, $message, $headers);
		mail('chris.mondor@gmail.com', $subject, $message, $headers);
		mail('arashghaneian@gmail.com', $subject, $message);
	}
	
}

?>